Specification for Writing Custom Code in Workflow
Background: For security reasons, [Python custom skill code] && [Advanced Orchestration - Code Node] require code writing specifications.
Supported Python Packages
1. Built-in Functions and Types
dict
sorted
filter
map
enumerate
2. Standard Library Modules
Data Processing
json
decimal
uuid
base64
hashlib
String Processing
re
(regular expressions)string
textwrap
difflib
(difference comparison)
Data Structures and Algorithms
copy
bisect
(binary search)heapq
(heap queue)statistics
(statistical calculations)
Mathematical Computation
math
operator
(operator functions)
Date and Time
datetime
time
calendar
Other Utilities
random
(random number generation)requests
(HTTP requests)
3. Type Annotations (typing
module)
typing
(the module itself)Any
Union
Optional
Literal
Final
ClassVar
TypeVar
Generic
Protocol
runtime_checkable
overload
cast
TYPE_CHECKING
NoReturn
List
Dict
Set
Tuple
FrozenSet
Deque
Counter
ChainMap
OrderedDict
DefaultDict
MutableMapping
MutableSequence
MutableSet
Mapping
Sequence
AbstractSet
Collection
Container
Iterable
Iterator
Reversible
Sized
Hashable
Callable
Awaitable
Coroutine
AsyncIterable
AsyncIterator
AsyncGenerator
Generator
ContextManager
AsyncContextManager
Syntax Specifications
Due to the use of secure environment isolation and other restrictions, writers must follow relevant specifications when writing code. Premise: Only built-in syntax and built-in libraries, as well as a limited set of standard libraries, are supported.
- Using the math module
import math
def calculate(a, b):
result = math.fsum([a, b])
return result
Incorrect usage:
from math import fsum
def calculate(a, b):
result = fsum([a, b])
return result
Explanation: Due to current import restrictions in the code block, only parent package imports are supported when importing packages. The syntax from a import b
is not supported.
- Using datetime
Correct usage:
import typing
from datetime import datetime
def get_weather(location: str, date: typing.Optional[str] = None) -> dict:
# Handle default date
if date is None:
formatted_date = datetime.datetime.now().strftime("%Y-%m-%d")
else:
try:
# Try to parse common date formats
if len(date) == 8 and date.isdigit():
# Handle YYYYMMDD format
date_obj = datetime.datetime.strptime(date, "%Y%m%d")
else:
# Try standard format YYYY-MM-DD
date_obj = datetime.datetime.strptime(date, "%Y-%m-%d")
formatted_date = date_obj.strftime("%Y-%m-%d")
except ValueError:
# If the format does not match, use the original input (may cause API call failure)
formatted_date = date
# This is mock data; in actual applications, a weather API may be called
weather_data = {
"location": location,
"date": formatted_date,
"forecast": "sunny",
"temperature": "25°C",
"wind": "light breeze"
}
return weather_data
Incorrect usage:
from typing import Optional, List, Dict, Any, Union, Callable
from datetime import datetime
...omitted...